﻿
using Models.JsonResultModel;
using Newtonsoft.Json;
using UtilsBase;

namespace ServiceWeb.WebClient
{
    public class ServiceAlive
    {
        public void run()
        {
            //这里不是多余的，如果这里不用 task.run，很难关闭进程，要等很久才能关闭
            Task.Run(() =>
            {
                setAlive();
            });
        }
        public void setAlive()
        {
            Thread.Sleep(2000);
            string result = "";
            while (result == "")
            {
                result = new UtilsHttpHelper().httpClientPost("http://localhost:8090/api/product/v1/Language/getPruductLanguage?pguid=cf4675f2-aa14-480b-abf9-59d89768e8be&languagecode=100", "");
                if (!String.IsNullOrEmpty(result))
                {
                    try
                    {
                        RespResultData respData = JsonConvert.DeserializeObject<RespResultData>(result);
                        if (respData.respCode == "200" && !string.IsNullOrEmpty(respData.data.ToString()))
                        {
                            break;
                        }
                    }
                    catch { }
                }
                Thread.Sleep(5000);
            }

            while (true)
            {
                result = new UtilsHttpHelper().httpClientPost("http://localhost:8090/AppAlive/test", "");
                Console.WriteLine(result);
                Thread.Sleep(1000 * 60);
            }
        }
    }
}
